
//
// 110616 - AH - (Fotballpuben *) Created.
// 110617 - AH - Finished implementation.
//

package org.soekrat.gui.swing.chat.convention;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;

import org.soekrat.engine.motor.Motor;
import org.soekrat.engine.sparewheel.ontology.ForestSpareWheelOntology;
import org.soekrat.engine.sparewheel.ontology.SpareWheelOntology;

/**
 * <p>
 *   {@link JCheckBox} to toggle if to populate the forest ontology of
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
@SuppressWarnings("serial")
public final class ToggleSpareWheelForestPopulation extends JCheckBox 
{
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param motor {@link Motor}.
   */
  public ToggleSpareWheelForestPopulation(final Motor motor)
  {
    super("Populate Sparewheel Forest");
    
    if (motor==null)
    {
      throw new NullPointerException("motor");
    }
    
    setSelected(motor.getSpareWheel().getSpoke(
      ForestSpareWheelOntology.class).getPopulate());
    
    addActionListener
    (
      new ActionListener() 
      {
        public void actionPerformed(ActionEvent e) 
        {
          SpareWheelOntology spoke=motor.getSpareWheel().getSpoke(
            ForestSpareWheelOntology.class);
          spoke.setPopulate(isSelected());
        
        }
      }
    );
  }
  
}
